package com.ymh.git.thread.juc.account;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by aivin on 2018/11/1.
 */
public class UserAccount {

    private final String name;//账户名称
    private int money;//账户余额

    private final Lock lock = new ReentrantLock();

    public Lock getLock() {
        return lock;
    }

    public UserAccount(String name, int money) {
        this.name = name;
        this.money = money;
    }

    public String getName() {
        return name;
    }

    public int getMoney() {
        return money;
    }

    @Override
    public String toString() {
        return "UserAccount{" +
                "name='" + name + '\'' +
                ", money=" + money +
                '}';
    }

    /**
     * 转入资金
     *
     * @param amount
     */
    public void inMoney(int amount) {
        money = money + amount;
    }

    /**
     * 转出资金
     *
     * @param amount
     */
    public void outMoney(int amount) {
        money = money - amount;
    }
}
